package com.ballcat.spring.cloud.learning.common;

import lombok.Data;

/**
 * @author pengshun
 * @date 2022-04-04 17:25
 * @description
 */
@Data
public class CommonResult<T>{

    private Integer code;

    private String message;

    private T data;

    public CommonResult() {
    }

    public CommonResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> CommonResult<T> ok(T data) {
        return new CommonResult<T>(200, "请求成功", data);
    }

    public static <T> CommonResult<T> ok(T data, String message) {
        return new CommonResult<T>(200, message, data);
    }

    public static CommonResult<String> fail(Integer code, String message) {
        return new CommonResult<>(code, message, null);
    }
}
